package com.ruoyi.quality.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quality.domain.CommonConstructionFile;
import com.ruoyi.quality.service.ICommonConstructionFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 施工规范文件Controller
 * 
 * @author mahl2
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/quality/constructionFile")
public class CommonConstructionFileController extends BaseController
{
    @Autowired
    private ICommonConstructionFileService commonConstructionFileService;

    /**
     * 查询施工规范文件列表
     */
    @PreAuthorize("@ss.hasPermi('quality:constructionFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommonConstructionFile commonConstructionFile)
    {
        startPage();
        List<CommonConstructionFile> list = commonConstructionFileService.selectCommonConstructionFileList(commonConstructionFile);
        return getDataTable(list);
    }

    /**
     * 导出施工规范文件列表
     */
    @PreAuthorize("@ss.hasPermi('quality:constructionFile:export')")
    @Log(title = "施工规范文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommonConstructionFile commonConstructionFile)
    {
        List<CommonConstructionFile> list = commonConstructionFileService.selectCommonConstructionFileList(commonConstructionFile);
        ExcelUtil<CommonConstructionFile> util = new ExcelUtil<CommonConstructionFile>(CommonConstructionFile.class);
        util.exportExcel(response, list, "施工规范文件数据");
    }

    /**
     * 获取施工规范文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('quality:constructionFile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commonConstructionFileService.selectCommonConstructionFileById(id));
    }

    /**
     * 新增施工规范文件
     */
    @PreAuthorize("@ss.hasPermi('quality:constructionFile:add')")
    @Log(title = "施工规范文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommonConstructionFile commonConstructionFile)
    {
        return toAjax(commonConstructionFileService.insertCommonConstructionFile(commonConstructionFile));
    }

    /**
     * 修改施工规范文件
     */
    @PreAuthorize("@ss.hasPermi('quality:constructionFile:edit')")
    @Log(title = "施工规范文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommonConstructionFile commonConstructionFile)
    {
        return toAjax(commonConstructionFileService.updateCommonConstructionFile(commonConstructionFile));
    }

    /**
     * 删除施工规范文件
     */
    @PreAuthorize("@ss.hasPermi('quality:constructionFile:remove')")
    @Log(title = "施工规范文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commonConstructionFileService.deleteCommonConstructionFileByIds(ids));
    }
}
